//
//  BuyFromWorldViewController.m
//  GouWoAi
//
//  Created by 赵佟越 on 16/5/5.
//  Copyright © 2016年 zhaotongyue. All rights reserved.
//

#import "BuyFromWorldViewController.h"
#import "BuyFromWorldCollectionViewCell.h"
#import "UIImageView+WebCache.h"


@interface BuyFromWorldViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property(nonatomic, strong)UICollectionView *collectionView;

@property(nonatomic, strong)NSArray *titleArr;

@property(nonatomic, strong)NSArray *detaileArr;

@property(nonatomic, strong)NSArray *goodsArr;

@end

@implementation BuyFromWorldViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self layoutNavigationBar];
    [self makeBaseUI];
    // Do any additional setup after loading the view.
}

#pragma mark - Private Methods
- (void)layoutNavigationBar {
    self.title = @"全球购";
    self.navigationController.navigationBar.translucent = NO;
    
    UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 22, 22)];
    rightButton.titleLabel.font = [UIFont systemFontOfSize:17];
    [rightButton setImage:[UIImage imageNamed:@"sysicon_n_64"] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(rightButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
}

- (void)makeBaseUI{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize =CGSizeMake((ZTY_SCREEN_WIDTH - 2) /2, (ZTY_SCREEN_HEIGHT - 64 - 49 - 8)/5);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.minimumInteritemSpacing = 1;
    layout.minimumLineSpacing = 1;
    layout.headerReferenceSize = CGSizeMake(self.view.frame.size.width, 0);
    
    // 创建CollectiongView
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:layout];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    [self.view addSubview:collectionView];
    [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"item"];
    collectionView.backgroundColor  = [UIColor getColorFromRGBString:@"#F6F6F6"];
    collectionView.contentInset = UIEdgeInsetsMake(2, 0, 2, 0);
    [self.collectionView registerClass:[BuyFromWorldCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    

    
}
#pragma mark - collectionView Delegate And DataSource


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"section, : %lu, item:%ld",indexPath.section, indexPath.item);
}

// item 的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}



- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    BuyFromWorldCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"item" forIndexPath:indexPath];
    // 2. 设置 cell
    switch (indexPath.item) {
        case 0:{
            UIImageView *myimageView = [[UIImageView alloc]init];
//            myimageView.backgroundColor = [UIColor orangeColor];
            myimageView.image = [UIImage imageNamed:@"user_pic_12"];
            [cell addSubview:myimageView];
            [myimageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell).offset((ZTY_SCREEN_WIDTH  - 2) /2 - (ZTY_SCREEN_HEIGHT - 64 - 49 - 6)/5);
                make.size.mas_equalTo(CGSizeMake((ZTY_SCREEN_HEIGHT - 64 - 49 - 6)/5 - 2, (ZTY_SCREEN_HEIGHT - 64 - 49 - 6)/5 - 2));
            }];
        }
            break;
        case 1:{
            UILabel *labelTitle = [[UILabel alloc]init];
            [cell addSubview:labelTitle];
            
            labelTitle.backgroundColor = [UIColor getColorFromRGBString:@"#C8EDFE"];
            labelTitle.textAlignment = NSTextAlignmentCenter;
            labelTitle.font = [UIFont systemFontOfSize:14];
            labelTitle.text = @"99 元任选 3件";
            [labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell).offset(13);
                make.top.equalTo(cell).offset(30);
                make.size.mas_equalTo(CGSizeMake(cell.frame.size.width - 26, 14));
                labelTitle.layer.cornerRadius = 5;
            }];
            labelTitle.layer.cornerRadius = 5;
            labelTitle.clipsToBounds = YES;
            
            
            UILabel *labeldetail = [[UILabel alloc]init];
            [cell addSubview:labeldetail];
            labeldetail.textColor = [UIColor getColorFromRGBString:@"909090"];
            labeldetail.text = @"全球洗护尖货随你挑";
            labeldetail.font = [UIFont systemFontOfSize:14];
            [labeldetail mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell).offset(13);
                make.top.equalTo(labelTitle.mas_bottom).offset(14);
                make.size.mas_equalTo(CGSizeMake(cell.frame.size.width - 26, 14));
            }];
            
            
        }
            break;
            
        default:{
            UILabel *labelTitle = [[UILabel alloc]init];
            [cell addSubview:labelTitle];
            
//            labelTitle.backgroundColor = [UIColor getColorFromRGBString:@"#C8EDFE"];
            labelTitle.textAlignment = NSTextAlignmentLeft;
            labelTitle.font = [UIFont systemFontOfSize:14];
            labelTitle.text = self.titleArr[indexPath.item - 2];
            [labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell).offset(13);
                make.top.equalTo(cell).offset(30);
                make.size.mas_equalTo(CGSizeMake(cell.frame.size.width, 14));
            }];
            
            
            UILabel *labeldetail = [[UILabel alloc]init];
            [cell addSubview:labeldetail];
            labeldetail.textColor = [UIColor getColorFromRGBString:@"909090"];
            labeldetail.text = self.detaileArr[indexPath.item - 2];
            labeldetail.font = [UIFont systemFontOfSize:13];
            [labeldetail mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(cell).offset(13);
                make.top.equalTo(labelTitle.mas_bottom).offset(14);
                make.size.mas_equalTo(CGSizeMake(cell.frame.size.width - 93, 14));
            }];
            
            UIImageView *pruductImageView = [[UIImageView alloc]init];
            [cell addSubview:pruductImageView];
            [pruductImageView sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:self.goodsArr[indexPath.row - 2]]];
            [pruductImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(labeldetail.mas_right).offset(8);
            }];
            
            
        }
            break;
    }
    
    
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}

#pragma mark - Button Action

- (void)rightButtonAction:(UIButton *)sender{
    // 搜索
}


#pragma mark - LazyLoad

- (NSArray *)titleArr{
    if (_titleArr == nil) {
        _titleArr = @[@"品牌特卖",@"美妆",@"母婴",@"保健",@"美食",@"居家",@"精选",@"精选"];
    }
    return _titleArr;
}

- (NSArray *)detaileArr{
    if (_detaileArr == nil) {
        _detaileArr = @[@"10分钟变baby",@"肌肤嫩到出水",@"读书卡链接",@"莱克斯顿",@"打开链接",@"是大家来看",@"第六课",@"是打开链接"];
    }
    return _detaileArr;
}

- (NSArray *)goodsArr{
    if (_goodsArr == nil) {
        _goodsArr = @[@"user_pic_13",@"user_pic_14",@"user_pic_15",@"user_pic_16",@"user_pic_15",@"user_pic_13",@"user_pic_14",@"user_pic_15"];
    }
    return _goodsArr;
}
     
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
